package com.ruoyi.service.impl;

import com.ruoyi.domain.UserMonitoring;
import com.ruoyi.mapper.UserMonitoringMapper;
import com.ruoyi.service.UserMonitoringService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 用户-健康监测数据
 *
 * @author lifei
 * @ClassName UserMonitoring
 */

@Service
public class UserMonitoringServiceImpl implements UserMonitoringService {

    @Autowired
    private UserMonitoringMapper userMonitoringMapper;

    /**
     * 获取最近五次血压数据
     * @param userId 用户ID
     * @return 血压数据列表
     */
    @Override
    public List<UserMonitoring> selectLastFiveBloodPressure(Long userId) {
        return userMonitoringMapper.selectLastFiveBloodPressure(userId);
    }

    @Override
    public List<UserMonitoring> selectLastFiveHeartRate(Long userId) {
        return userMonitoringMapper.selectLastFiveHeartRate(userId);
    }

    /**
     * 获取最近五个月体重数据
     * @param userId 用户ID
     * @return 体重数据列表
     */
    @Override
    public Map<String, List<UserMonitoring>> getLastFiveMonthsWeight(Long userId) {
        List<UserMonitoring> weightDataList = userMonitoringMapper.selectWeightByLastFiveMonths(userId);

        // 按月份分组
        return weightDataList.stream()
                .collect(Collectors.groupingBy(UserMonitoring::getMonth));
    }
}

